package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.T04VO;
import com.ruoyi.common.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.T04;
import com.ruoyi.service.IT04Service;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消费总记录Controller
 *
 * @author ruoyi
 * @date 2024-08-04
 */
@RestController
@RequestMapping("/system/T04")
public class T04Controller extends BaseController
{
    @Autowired
    private IT04Service t04Service;

    /**
     * 查询消费总记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:T04:list')")
    @GetMapping("/list")
    @Log(title = "消费总记录")
    public TableDataInfo list(T04 t04)
    {
        startPage();
        List<T04> list = t04Service.selectT04List(t04);
        return getDataTable(list);
    }

    /**
     * 导出消费总记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:T04:export')")
    @Log(title = "消费总记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, T04 t04)
    {
        List<T04> list = t04Service.selectT04List(t04);
        ExcelUtil<T04> util = new ExcelUtil<T04>(T04.class);
        util.exportExcel(response, list, "消费总记录数据");
    }

    /**
     * 获取消费总记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:T04:query')")
    @Log(title = "消费总记录")
    @GetMapping(value = "/{F0401}")
    public AjaxResult getInfo(@PathVariable("F0401") Long F0401)
    {
        return success(t04Service.selectT04ByF0401(F0401));
    }

    /**
     * 新增消费总记录
     */
    @PreAuthorize("@ss.hasPermi('system:T04:add')")

    @Log(title = "消费总记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody T04 t04)
    {
        return toAjax(t04Service.insertT04(t04));
    }

    /**
     * 修改消费总记录
     */
    @PreAuthorize("@ss.hasPermi('system:T04:edit')")
    @Log(title = "消费总记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody T04 t04)
    {
        return toAjax(t04Service.updateT04(t04));
    }

    /**
     * 删除消费总记录
     */
    @PreAuthorize("@ss.hasPermi('system:T04:remove')")
    @Log(title = "消费总记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{F0401s}")
    public AjaxResult remove(@PathVariable Long[] F0401s)
    {
        return toAjax(t04Service.deleteT04ByF0401s(F0401s));
    }

    @GetMapping("/getQueryRecords")
    @ApiOperation("记录查询总表")
    public Result getQueryRecords() {
        List<T04VO> list = t04Service.getQueryRecords();
        if (list.size()==0){
            return new Result("无数据");
        }
        return Result.success(list,"OK");
    }
}
